<script>
	export default {
		onLaunch() {
			this.appInit()
		},
		onShow() {
			setTimeout(() => {
				// #ifdef APP-PLUS 
				plus.navigator.closeSplashscreen()
				// #endif
			}, 3000)
		},
		onHide() {
		},
		onLoad() {
		},
		methods:{
			appInit(){
				//检测更新
				const currentVersion = uni.getSystemInfoSync('currentVersion');
				// console.log(currentVersion.appWgtVersion)
				console.log(uni.getSystemInfoSync())				
				if (!currentVersion) {
				        uni.reLaunch({
				            url: "/pages/login/login",
				            success: () => {
				                //跳转完页面后再关闭启动页
				               plus.navigator.closeSplashscreen();
				            }
				       })
				    } else {
				        plus.navigator.closeSplashscreen(); //关闭启动页，进入首页
				    }
				//this.checkUpdate()
			},
			checkUpdate(){
				//请求接口，判断是否需要升级
				// console.log(uni.getSystemInfoSync())
				uni.getSystemInfoSync().appVersionCode
				const newVersionName = "V1.2.0" //线上最新版本名
				const newVersionCode = 20; //线上最新版本号
				const selfVersionCode = Number(uni.getSystemInfoSync().appVersionCode) //当前App版本号
				uni.publicJs.post('/app/index?cmd=appUpdate',
					{
						
					},
					res=>{
						console.log(res)
						//线上版本号高于当前，进行在线升级
						if (selfVersionCode < newVersionCode) {
							let platform = uni.getSystemInfoSync().platform //手机平台
							//安卓手机弹窗升级
							if (platform === 'id') {
								uni.navigateTo({
									url: '/pages/index/upgrade'
								})
							}
							//IOS无法在线升级提示到商店下载
							else {
								uni.showModal({
									title: '发现新版本 ' + newVersionName,
									content: '暂无开发',
									showCancel: false
								})
							}
						}
					}
				)
				
			}
		}
	}
</script>

<style>
	/*每个页面公共css */
	@import "./static/css/iconfont.css";
	@import "./static/css/ccUI.css";
	view{font-size: 28rpx;}
	page {
		background-color: #F2F4F8;
	}
</style>
